/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nxlv2.nomad.view;

import com.nxlv2.nomad.accessdb.services.UtilisateurServices;
import com.nxlv2.nomad.businessobjects.Utilisateur;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;

/**
 *
 * @author Administrateur
 */
public class LoginAction extends AbstractAction {
    private final Login loginUI;
   
    public LoginAction(Login loginUI,String texte){
        super(texte);   
        this.loginUI = loginUI;            
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        
        Utilisateur user = new Utilisateur(loginUI.getEmailTField().getText(),loginUI.getMdpTField().getText());
        UtilisateurServices srv = new UtilisateurServices();
        boolean exist = srv.verifierConnection(user);
        
        if(exist){
            user = srv.get(user.getMail());
            loginUI.setConnect(true);
            loginUI.setVisible(false);
            Welcome welcomeUI = new Welcome(user);
            welcomeUI.setVisible(true);
            loginUI.dispose();
        } else {
            loginUI.getEreurLabel().setText("Erreur d'identifiant ou de mot de passe");
        }             
    }

}
